<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
</head>
<body>
<form class="form-horizontal m-t" id="editUserForm" action="#" method="post">
    <div class="modal-content animated bounceInRight">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">关闭</span>
            </button>
            <h4 class="modal-title">编辑管理员</h4>
        </div>
        <div class="modal-body">

            <div class="form-group">
                <label class="col-sm-3 control-label">用户名：</label>
                <div class="col-sm-8">
                    <input id="e-username" name="e-username" class="form-control" type="text" th:value="${user.username}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">手机号：</label>
                <div class="col-sm-8">
                    <input id="e-phone" name="e-phone" class="form-control" type="number" th:value="${user.phone}">
                </div>
            </div>
            <div class="form-group" id="e-roles" th:if="${root&&!own}">
                <label class="col-sm-3 control-label">角色(可多选)：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <select data-placeholder="请选择角色(可多选)" class="chosen-select" multiple style="width:350px;"
                                tabindex="4" name="e-roles" id="roles">
                            <th:block th:each="role:${roles}">
                                <option th:value="${role.id}" th:text="${role.roleDesc}"></option>
                            </th:block>
                        </select>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">密码：</label>
                <div class="col-sm-8">
                    <input id="e-password" name="e-password" class="form-control" type="password" placeholder="可选">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">确认密码：</label>
                <div class="col-sm-8">
                    <input id="e-confirm_password" name="e-confirm_password" class="form-control" type="password" placeholder="可选">
                    <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 请再次输入您的密码</span>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">E-mail：</label>
                <div class="col-sm-8">
                    <input id="e-email" name="e-email" class="form-control" type="email" th:value="${user.email}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">联系地址：</label>
                <div class="col-sm-8">
                    <input id="e-address" name="e-address" class="form-control" type="text" th:value="${user.address}">
                </div>
            </div>
            <div class="col-sm-12" style="display:none;">
                <span class="help-block m-b-none" id="e-errTip" style="color: #ac2925"><i class="fa fa-info-circle"></i>这里显示错误信息</span>
            </div>

        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" type="submit">保存</button>
        </div>
    </div>
</form>
<script th:src="@{/js/users/editAdmin.js}"></script>
<script th:inline="javascript">
    var config = {
        '.chosen-select': {},
        '.chosen-select-deselect': {
            allow_single_deselect: true
        },
        '.chosen-select-no-single': {
            disable_search_threshold: 10
        },
        '.chosen-select-no-results': {
            no_results_text: 'Oops, nothing found!'
        },
        '.chosen-select-width': {
            width: "95%"
        }
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }
    var roles=[[${user.roles}]]
    var rolesArr=[]
    for (var i in roles) {
        rolesArr[i]=roles[i].id
    }
    $(".chosen-select").val(rolesArr);
    $(".chosen-select").trigger("chosen:updated");
</script>
</body>
</html>
